package jnpf.service.impl;

import jnpf.entity.Whu_recordEntity;
import jnpf.mapper.Whu_recordMapper;
import jnpf.service.Whu_recordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;


import jnpf.model.whu_record.Whu_recordPagination;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * whu_record
 * 版本： V3.2.0
 * 版权： 引迈信息技术有限公司（https://www.jnpfsoft.com）
 * 作者： JNPF开发平台组
 * 日期： 2025-06-28
 */
@Service

public class Whu_recordServiceImpl extends ServiceImpl<Whu_recordMapper, Whu_recordEntity> implements Whu_recordService {

    @Autowired
    private UserProvider userProvider;






    @Override
    public List<Whu_recordEntity> getList(Whu_recordPagination whu_recordPagination){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
                    QueryWrapper<Whu_recordEntity> whu_recordQueryWrapper=new QueryWrapper<>();
            int whu_recordNum =0;
			if(StringUtil.isNotEmpty(whu_recordPagination.getInid())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getInid,whu_recordPagination.getInid());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getDate())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getDate,whu_recordPagination.getDate());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getRecord())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getRecord,whu_recordPagination.getRecord());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getVedio())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getVedio,whu_recordPagination.getVedio());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getVoice())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getVoice,whu_recordPagination.getVoice());
                    }

        if(AllIdList.size()>0){
            whu_recordQueryWrapper.lambda().in(Whu_recordEntity::getId, AllIdList);
        }
        //排序
        if(StringUtil.isEmpty(whu_recordPagination.getSidx())){
        whu_recordQueryWrapper.lambda().orderByDesc(Whu_recordEntity::getId);
        }else{
        whu_recordQueryWrapper="asc".equals(whu_recordPagination.getSort().toLowerCase())?whu_recordQueryWrapper.orderByAsc(whu_recordPagination.getSidx()):whu_recordQueryWrapper.orderByDesc(whu_recordPagination.getSidx());
        }
        if((total>0 && AllIdList.size()>0) || total==0){
        Page<Whu_recordEntity> page=new Page<>(whu_recordPagination.getCurrentPage(), whu_recordPagination.getPageSize());
        IPage<Whu_recordEntity> userIPage=this.page(page, whu_recordQueryWrapper);
        return whu_recordPagination.setData(userIPage.getRecords(),userIPage.getTotal());
        }else{
            List<Whu_recordEntity> list = new ArrayList();
            return whu_recordPagination.setData(list, list.size());
        }
    }
    @Override
    public List<Whu_recordEntity> getTypeList(Whu_recordPagination whu_recordPagination,String dataType){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
		int total=0;
                    QueryWrapper<Whu_recordEntity> whu_recordQueryWrapper=new QueryWrapper<>();
            int whu_recordNum =0;
			if(StringUtil.isNotEmpty(whu_recordPagination.getInid())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getInid,whu_recordPagination.getInid());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getDate())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getDate,whu_recordPagination.getDate());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getRecord())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getRecord,whu_recordPagination.getRecord());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getVedio())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getVedio,whu_recordPagination.getVedio());
                    }

			if(StringUtil.isNotEmpty(whu_recordPagination.getVoice())){
            whu_recordNum++;
            whu_recordQueryWrapper.lambda().like(Whu_recordEntity::getVoice,whu_recordPagination.getVoice());
                    }

		if(AllIdList.size()>0){
        whu_recordQueryWrapper.lambda().in(Whu_recordEntity::getId, AllIdList);
				}
        //排序
        if(StringUtil.isEmpty(whu_recordPagination.getSidx())){
        whu_recordQueryWrapper.lambda().orderByDesc(Whu_recordEntity::getId);
        }else{
        whu_recordQueryWrapper="asc".equals(whu_recordPagination.getSort().toLowerCase())?whu_recordQueryWrapper.orderByAsc(whu_recordPagination.getSidx()):whu_recordQueryWrapper.orderByDesc(whu_recordPagination.getSidx());
        }
        if("0".equals(dataType)){
            if((total>0 && AllIdList.size()>0) || total==0){
                Page<Whu_recordEntity> page=new Page<>(whu_recordPagination.getCurrentPage(), whu_recordPagination.getPageSize());
                IPage<Whu_recordEntity> userIPage=this.page(page, whu_recordQueryWrapper);
                return whu_recordPagination.setData(userIPage.getRecords(),userIPage.getTotal());
            }else{
                List<Whu_recordEntity> list = new ArrayList();
                return whu_recordPagination.setData(list, list.size());
            }
        }else{
            return this.list(whu_recordQueryWrapper);
        }
    }

    @Override
    public Whu_recordEntity getInfo(String id){
        QueryWrapper<Whu_recordEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(Whu_recordEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(Whu_recordEntity entity){
        this.save(entity);
    }

    @Override
    public boolean update(String id, Whu_recordEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(Whu_recordEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法

}